home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue61 / Actions / ActionAppU.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-05-16  |  1.1 KB  |  50 lines

  1. unit ActionAppU;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ActnList, ImgList;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     edtEntry: TEdit;
  12.     Label1: TLabel;
  13.     lstEntries: TListBox;
  14.     btnAddString: TButton;
  15.     ActionList: TActionList;
  16.     ImageList: TImageList;
  17.     actAddString: TAction;
  18.     procedure actAddStringExecute(Sender: TObject);
  19.     procedure actAddStringUpdate(Sender: TObject);
  20.   private
  21.     { Private declarations }
  22.   public
  23.     { Public declarations }
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.DFM}
  32.  
  33. procedure TForm1.actAddStringExecute(Sender: TObject);
  34. begin
  35.   lstEntries.Items.Add( Trim( edtEntry.Text ) );
  36.   //Give focus back to edit
  37.   edtEntry.SetFocus;
  38.   //Highlight edit's contents so it can be replaced by overtyping
  39.   edtEntry.SelectAll;
  40. end;
  41.  
  42. procedure TForm1.actAddStringUpdate(Sender: TObject);
  43. begin
  44.   (Sender as TAction).Enabled :=
  45.     ( Length( Trim( edtEntry.Text ) ) > 0 ) and
  46.     ( lstEntries.Items.IndexOf( Trim( edtEntry.Text ) ) = -1 )
  47. end;
  48.  
  49. end.
  50.